<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


<!-- remove old header -->


<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>cogen API Reference Documentation
        - Class: Scheduler</title><meta name="MSSmartTagsPreventParsing" content="true" /><meta http-equiv="imagetoolbar" content="no" /><link href="css/default.css" rel="stylesheet" type="text/css" /><link href="css/pygments.css" rel="stylesheet" type="text/css" />
    <!-- <link rel="shortcut icon" href="/images/favicon.ico" type="image/vnd.microsoft.icon"/> -->
    <link rel="stylesheet" href="css/apydia.css" type="text/css" />
    <script src="js/jquery-1.2.1.pack.js" type="text/javascript"></script>
    <script src="js/apydia.js" type="text/javascript"></script>
	<link rel="icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
    <div id="page">
        <div id="browser">
            <div class="browser-section">
                <h2>Module Index</h2>
                <ul>
                    <li>
                        <a href="cogen.html">cogen</a>
                    </li><li>
                        <a href="cogen.common.html">cogen.common</a>
                    </li><li>
                        <a href="cogen.core.html">cogen.core</a>
                    </li><li>
                        <a href="cogen.core.coroutines.html">cogen.core.coroutines</a>
                    </li><li>
                        <a href="cogen.core.events.html">cogen.core.events</a>
                    </li><li>
                        <a href="cogen.core.proactors.html">cogen.core.proactors</a>
                    </li><li>
                        <a href="cogen.core.proactors.base.html">cogen.core.proactors.base</a>
                    </li><li>
                        <a href="cogen.core.proactors.epoll_impl.html">cogen.core.proactors.epoll_impl</a>
                    </li><li>
                        <a href="cogen.core.proactors.poll_impl.html">cogen.core.proactors.poll_impl</a>
                    </li><li>
                        <a href="cogen.core.proactors.select_impl.html">cogen.core.proactors.select_impl</a>
                    </li><li>
                        <a href="cogen.core.pubsub.html">cogen.core.pubsub</a>
                    </li><li>
                        <a href="cogen.core.queue.html">cogen.core.queue</a>
                    </li><li class="active">
                        <a href="cogen.core.schedulers.html">cogen.core.schedulers</a>
                    </li><li>
                        <a href="cogen.core.sockets.html">cogen.core.sockets</a>
                    </li><li>
                        <a href="cogen.core.util.html">cogen.core.util</a>
                    </li><li>
                        <a href="cogen.web.html">cogen.web</a>
                    </li><li>
                        <a href="cogen.web.async.html">cogen.web.async</a>
                    </li><li>
                        <a href="cogen.web.wsgi.html">cogen.web.wsgi</a>
                    </li>
                </ul>
            </div>
            <div class="browser-section">
                <h2>cogen.core.schedulers</h2>
                <ul>
                    <li class="active">
                        <a href="cogen.core.schedulers.Scheduler.html">Scheduler</a>
                    </li>
                </ul>
            </div>
            <div class="browser-section">
                <h2>Constructor</h2>
                <ul>
                    <li>
                        <a href="cogen.core.schedulers.Scheduler.html#constructor">__init__</a>
                    </li>
                </ul>
            </div>
            <div class="browser-section">
                <h2>Methods</h2>
                <ul>
                    <li>
                        <a href="cogen.core.schedulers.Scheduler.html#method-add">add</a>
                    </li><li>
                        <a href="cogen.core.schedulers.Scheduler.html#method-handle_timeouts">handle_timeouts</a>
                    </li><li>
                        <a href="cogen.core.schedulers.Scheduler.html#method-iter_run">iter_run</a>
                    </li><li>
                        <a href="cogen.core.schedulers.Scheduler.html#method-next_timer_delta">next_timer_delta</a>
                    </li><li>
                        <a href="cogen.core.schedulers.Scheduler.html#method-process_op">process_op</a>
                    </li><li>
                        <a href="cogen.core.schedulers.Scheduler.html#method-run">run</a>
                    </li><li>
                        <a href="cogen.core.schedulers.Scheduler.html#method-stop">stop</a>
                    </li>
                </ul>
            </div>
        </div>
        <div id="content">
    <h1>Class: cogen.core.schedulers.Scheduler</h1>
    <div class="docstring rst"><p>Basic deque-based scheduler with timeout support and primitive
prioritisaiton parameters.</p>
<p>Usage:</p>
<div class="source"><pre><span class="n">mysched</span> <span class="o">=</span> <span class="n">Scheduler</span><span class="p">(</span><span class="n">proactor</span><span class="o">=</span><span class="n">DefaultProactor</span><span class="p">,</span>
        <span class="n">default_priority</span><span class="o">=</span><span class="n">priority</span><span class="o">.</span><span class="n">LAST</span><span class="p">,</span> <span class="n">default_timeout</span><span class="o">=</span><span class="bp">None</span><span class="p">)</span>
</pre></div>
<ul class="simple">
<li>proactor: a proactor class to use</li>
<li>default_priority: a default priority option for operations that do not
set it. check <a class="reference" href="cogen.core.util.priority.html">priority</a>.</li>
<li>default_timeout: a default timedelta or number of seconds to wait for
the operation, -1 means no timeout.</li>
</ul>
</div>
    <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/schedulers.py#43">View source</a>
    </li>
</ul>
    <div>
        <h2>Constructor</h2>
        <h3 id="constructor">
            __init__
            <span class="args">(self, proactor=&lt;class 'cogen.core.proactors.epoll_impl.EpollProactor'&gt;, default_priority=0, default_timeout=None, proactor_resolution=0.01, proactor_greedy=True, ops_greedy=False, proactor_multiplex_first=None, proactor_default_size=None)</span>
        </h3>
        <div class="docstring rst"></div>
        <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
    </div>
    <div>
        <h2>Methods</h2>
            <h3 id="method-add">
                add
                <span class="args">(self, coro, args=(), kwargs={}, first=True)</span>
            </h3>
            <div class="docstring rst"><p>Add a coroutine in the scheduler. You can add arguments
(_args_, _kwargs_) to init the coroutine with.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="method-handle_timeouts">
                handle_timeouts
                <span class="args">(self)</span>
            </h3>
            <div class="docstring rst"><p>Handle timeouts. Raise timeouted operations with a OperationTimeout
in the associated coroutine (if they are still alive and the operation
hasn't actualy sucessfuly completed) or, if the operation has a
weak_timeout flag, update the timeout point and add it back in the
heapq.</p>
<p>weak_timeout notes:</p>
<ul class="simple">
<li>weak_timeout means a last_update attribute is updated with
a timestamp of the last activity in the operation - for example, a
may recieve new data and not complete (not enough data, etc)</li>
<li>if there was activity since the last time we've cheched this
timeout we push it back in the heapq with a timeout value we'll check
it again</li>
</ul>
<p>Also, we call a cleanup on the op, only if cleanup return true we raise
the timeout (finalized isn't enough to check if the op has completed
since finalized is set when the operation gets back in the coro - and
it might still be in the Scheduler.active queue when we get to this
timeout - well, this is certainly a problem magnet: TODO: fix_finalized)</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="method-iter_run">
                iter_run
                <span class="args">(self)</span>
            </h3>
            <div class="docstring rst"><p>The actual processing for the main loop is here.</p>
<p>Running the main loop as a generator (where a iteration is a full
sched, proactor and timers/timeouts run) is usefull for interleaving
the main loop with other applications that have a blocking main loop and
require cogen to run in the same thread.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="method-next_timer_delta">
                next_timer_delta
                <span class="args">(self)</span>
            </h3>
            <div class="docstring rst"><p>Returns a timevalue that the proactor will wait on.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="method-process_op">
                process_op
                <span class="args">(self, op, coro)</span>
            </h3>
            <div class="docstring rst"><p>Process a (op, coro) pair and return another pair. Handles exceptions.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="method-run">
                run
                <span class="args">(self)</span>
            </h3>
            <div class="docstring rst"><p>This is the main loop.
This loop will exit when there are no more coroutines to run or stop has
been called.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="method-stop">
                stop
                <span class="args">(self)</span>
            </h3>
            <div class="docstring rst"></div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
    </div>
        </div>
        <div id="footer">
            Generated with <a href="http://apydia.ematia.de/" class="extern">
            Apydia 0.0.3</a>
        </div>
    </div>
</body>
</html>